<template>
  <div class="container" @click="handleGalleryClick">
    <div class="wrapper">
      <swiper :options="swiperOptions">
        <swiper-slide v-for="(img, index) of imgs" :key="index">
          <img class="gallery-img" :src="img">
        </swiper-slide>
        <div class="swiper-pagination"  slot="pagination"></div>
      </swiper>
    </div>
  </div>
</template>

<script>
export default{
  name: 'CommonGallery',
  props: {
    imgs: {
      type: Array,
      default () { // 如果不传参数 该函数调用一个固定小数组
        return []
      }
    }
  },
  data () {
    return {
      swiperOptions: {
        pagination: '.swiper-pagination',
        paginationType: 'fraction', // 官网参数 paginationType（‘bullets’  圆点（默认）‘fraction’  分式 ‘progress’  进度条‘custom’ 自定义）【接近在图片底部】
        observeParents: true,
        observer: true
      }
    }
  },
  methods: {
    handleGalleryClick () {
      this.$emit('close')
    }
  }
}
</script>

<style lang="stylus" scoped>
  .container >>> .swiper-container
    overflow inherit
  .container
    z-index 99
    display flex // 设置为弹性布局
    flex-direction column // 规定项目的方向 为垂直(默认从上到下)
    justify-content center // 规定项目的位置布局
    position fixed // 定位 相对浏览器绝对定位
    left 0
    right 0
    top 0
    bottom 0
    background #000
    .wrapper
      // overflow hidden
      width 100%
      height 0
      padding-bottom 100%
      // background #fff
      .gallery-img
        width 100%
      .swiper-pagination
        color #fff
        bottom -.3rem
</style>
